'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
    const {router, controller} = app;
    const captcha = app.middleware.captcha({}, app);

    String.prototype.format = function () {
        let formatted = this;
        for (let arg in arguments) {
            formatted = formatted.replace("{" + arg + "}", arguments[arg]);
        }
        return formatted;
    };


    const dateFormat = function (fmt = "yyyy-MM-dd hh:mm:ss") {
        let o = {
            "M+": this.getMonth() + 1, //月份
            "d+": this.getDate(), //日
            "h+": this.getHours(), //小时
            "m+": this.getMinutes(), //分
            "s+": this.getSeconds(), //秒
            "q+": Math.floor((this.getMonth() + 3) / 3), //季度
            "S": this.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) {
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        }
        for (var k in o) {
            if (new RegExp("(" + k + ")").test(fmt)) {
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ?
                    (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
            }
        }
        return fmt;
    };

    Date.prototype.formatDate = dateFormat;

    Number.prototype.hlFixed = function (t = 4) {
        if (isNaN(this)) return this;
        let h = 1, o = this;
        this < 0 && (h = -1, o = 0 - this);
        let r = Math.floor(t) >= 0 ? Math.floor(t) : 0, i = Math.round(o * Math.pow(10, r + 6)) / Math.pow(10, 6);
        return h * Math.round(i) / Math.pow(10, r)
    };

    const prefix = '/courseapp';
    router.get('/MP_verify_1tS0LINY4TFkPf4X.txt', controller.wechat.MP_verify);

    router.get(`${prefix}/user/getUserInfo`,controller.user.getUserInfo);


    router.get(`${prefix}/common/product/list`, controller.product.getProductList);
    router.get(`${prefix}/common/product/:productId`, controller.product.getProductDetail);
    router.get(`${prefix}/common/bankCard/list`,controller.bank.getBankCardList);

    router.post(`${prefix}/complaint`,controller.complaint.addComplaint);
    router.get(`${prefix}/complaint/list`,controller.complaint.getComplaintList);
    router.post(`${prefix}/bank`,controller.bank.addBank);
    router.get(`${prefix}/bank/list`,controller.bank.getBankList);
    router.get(`${prefix}/bank/:id`,controller.bank.getBankDetail);

    router.post(`${prefix}/product/apply`,controller.product.applyProduct);
    router.post(`${prefix}/user/kyc`,controller.user.userKyc);
    router.post(`${prefix}/user/baseInfo`,controller.user.userBaseInfo);
    router.post(`${prefix}/user/contactPerson`,controller.user.contactPerson);


    router.post(`${prefix}/publish/upload/file`, controller.common.uploadFile);





    router.get(`${prefix}/oauth2/authorize`, controller.wechat.oauth2Authorize);






};
